/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package services.implementation;

import java.util.List;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import entity.Description;
import entity.Notes;
import services.IDescriptionsService;

/**
 *
 * @author smile
 */
@Stateless
@LocalBean
public class DescriptionsService extends GenericServices implements IDescriptionsService {
    @PersistenceContext(unitName = "snPU")
    private EntityManager em;

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")

    @Override
    public boolean addDescription(Object object) {
        return this.insert(object);
    }

    @Override
    public boolean deleteDescription(Object object) {
        return this.delete(object);
    }

    @Override
    public boolean updateDescription(Object object) {
        return this.update(object);
    }

    @Override
    public List<Description> getAllDescriptions() {
        return this.em.createNamedQuery("Description.findAll").getResultList();
    }

    @Override
    public Description getDescriptionById(Integer id) {
        return this.em.find(Description.class, id);
    }
    
    public List<Description> getDescriptionByNote(Notes idNote) {
        try{            
            return this.em.createNamedQuery("Description.findDescriptionByNote")
                .setParameter("idNotes", idNote)
                .getResultList();
        }catch (Exception e){
            System.out.println(e.getMessage());
            return null;
        } 
    }
}
